package com.lxw.report.meta.config.shiro;

import com.alibaba.fastjson.JSON;
import com.lxw.report.meta.vo.ResultVo;
import org.apache.shiro.web.filter.authc.UserFilter;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;

/**
 * @author lxw
 * @time 2022/3/17 16:59
 */
public class ShiroUserFilter extends UserFilter {

    @Override
    protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws Exception {
        HttpServletResponse httpServletResponse = (HttpServletResponse) response;
        httpServletResponse.setStatus(200);
        httpServletResponse.setContentType("application/json;charset=utf-8");
        PrintWriter out = httpServletResponse.getWriter();
        out.println(JSON.toJSONString(ResultVo.failLogin("会话失效")));
        out.flush();
        out.close();
        return false;
    }


}
